import React from "react";
import dayjs from "dayjs";
import { Button, Space } from "antd";
import { authButton } from "@/common";

/**@description 列表表格字段 */
const getColumns = ({ open = Function, handleDelete = Function, openPreview = Function }) => {
    const columns = [

        {
            title: "发布时间",
            key: "createDate",
            dataIndex: "createDate",
            width: 180,
        },
        {
            title: "标题",
            key: "title",
            dataIndex: "title",
        },
        {
            title: "作者",
            key: "author",
            dataIndex: "author",
            width: 200,
        },
        {
            title: "操作",
            key: "action",
            dataIndex: "action",
            width: 200,
            render: (text, record) => {
                return (
                    <Space>
                        {
                            authButton("context:article:list:preview") && <Button type="link" onClick={() => openPreview({ type: "preview", record: record })}>预览</Button>
                        }
                        {
                            authButton("context:article:list:edit") && <Button type="link" onClick={() => open({ type: "update", record: record })}>修改</Button>
                        }
                        {
                            authButton("context:article:list:delete") && <Button type="link" danger onClick={() => handleDelete(record?.id)}>删除</Button>
                        }
                    </Space>
                )
            }
        },
    ];
    return columns;
}

export default getColumns;